﻿package app.view.components.guiDima 
{
	import app.view.components.guiDima.slideShowD.Image;
	import app.view.events.UIEvent;
	import com.snzflash.components.list.ListItemRenderer;
	import flash.display.LineScaleMode;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * Бокс только с картинкой и рамкой
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@yandex.ru
	 */
	public class ImageItem extends ListItemRenderer
	{
		
		//	public
		public static const WIDTH:Number = 150;
		public static const HEIGHT:Number = 115;
		//	private
		private var _image:Image;
		private var _border:Shape;
		private var _mask:Shape;
		//	const
		private static const ROUND:Number = 14;
		//	CONSTRUCTOR
		public function ImageItem() 
		{
			super();
		}
		
		//	METHODS
		//	private
		override protected function init():void
		{
			super.init();
			//trace('+++');
			graphics.beginFill(0xff0000,0);
			graphics.drawRect(0, 0, WIDTH, HEIGHT);
			graphics.endFill();
			
			_image = new Image(WIDTH, HEIGHT, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image);
			
			_border = new Shape();
			_border.graphics.lineStyle(1, 0x000000, 1, true, LineScaleMode.NONE);
			_border.graphics.drawRoundRect(0, 0, WIDTH, HEIGHT, ROUND);
			addChild(_border);
			
			_mask = new Shape();
			_border.graphics.lineStyle(1, 0x000000, 1, true, LineScaleMode.NONE);
			_border.graphics.drawRoundRect(0, 0, WIDTH, HEIGHT, ROUND);
			addChild(_mask);
			_image.mask = _mask;
			
		};
		
		private function setEvents():void
		{
			doubleClickEnabled = true;
			//addEventListener(MouseEvent.ROLL_OVER, onItemOver);
			//addEventListener(MouseEvent.ROLL_OUT, onItemOut);
			addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function removeEvents():void
		{
			//removeEventListener(MouseEvent.ROLL_OVER, onItemOver);
			//removeEventListener(MouseEvent.ROLL_OUT, onItemOut);
			removeEventListener(MouseEvent.CLICK, onClick);
		}
		
		override public function destroy():void 
		{
			super.destroy();
			
			removeEvents();
			
			_image.destroy();
			removeChild(_image);
			
			removeChild(_mask);
			removeChild(_border);
			
			
		};
		
		override public function get data():Object { return super.data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			//trace('data', data);
			
			if (_data) 
			{
				_image.loadImage(_data.image);
			}
			
			
			selected = false;
		};
		
		override public function get selected():Boolean { return _selected; };
		
		override public function set selected(value:Boolean):void 
		{
			_selected = value;
			
			/*if (_selected==true) 
			{
				removeEvents();
				buttonMode = useHandCursor = false;
			}else
			{
				setEvents();
				buttonMode = useHandCursor = true;
			}*/
			
			setEvents();
			buttonMode = useHandCursor = true;
		};
		
		private function onClick(e:MouseEvent):void 
		{
			//trace('click popup');
			
			var ev:UIEvent = new UIEvent(UIEvent.CLICK_30_INTERVIEW_WINNER);
			ev.data = data;
			dispatchEvent(ev);
			
		}
		
		
		//	----------------------------------------------------------------------------------
		
		//	GETTERS/SETTERS
		
		//	----------------------------------------------------------------------------------
		
		//	HANDLERS
	}

}